package com.example.compete.controller;

import com.example.compete.DTO.EducationTypeDTO;
import com.example.compete.DTO.ExecutiveDTO;
import com.example.compete.DTO.PostTypeDTO;
import com.example.compete.DTO.SexTypeDTO;
import com.example.compete.mapper.ExecutiveMapper;
import com.example.compete.service.ExecutiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@ResponseBody
@CrossOrigin
@RequestMapping("/executive")
public class ExecutiveController {

    @Autowired
    private ExecutiveService executiveService;

    //查看全部高管信息
    @GetMapping("goShowAllExecutive")
    public List<ExecutiveDTO> executiveDTOList(@RequestParam("id")String companyId) {
    	return executiveService.selectAllByCompanyId(companyId);
    }
    
    //查看教育程度信息
    @GetMapping("goShowAllEducationType")
    public List<EducationTypeDTO> educationTypeDTOList() {
    	return executiveService.findAllEducationType();
    }

    //查看职务信息
    @GetMapping("goShowAllPostType")
    public List<PostTypeDTO> postTypeDTOList() {
    	return executiveService.findAllPostType();
    }
    
    //查看性别信息
    @GetMapping("goShowAllSexType")
    public List<SexTypeDTO> sexTypeDTOList() {
    	return executiveService.findAllSexType();
    }
    
    //查看单条高管信息(id)
    @GetMapping("goShowExecutive")
    public ExecutiveDTO executiveDTOS(@RequestParam("id")String executiveId) {
        return executiveService.findByExecutiveId(executiveId);
    }

    //修改高管信息(id)
    @PostMapping("editExecutive")
    public void editExecutive(@RequestBody ExecutiveDTO executiveDTO) {
        executiveService.updateExecutive(executiveDTO);
    }

    //增加高管信息
    @PostMapping("addExecutive")
    public ExecutiveDTO addExecutive(@RequestBody ExecutiveDTO executiveDTO) {
        executiveService.add(executiveDTO);
        List<ExecutiveDTO> comExecutiveDTOs=executiveService.selectAllByCompanyId(executiveDTO.getCompanyId());
        return comExecutiveDTOs.get(comExecutiveDTOs.size()-1);
    }

    //删除高管信息(id)
    @GetMapping("deleteExecutive")
    public boolean deleteExecutive(@RequestParam("id") String executiveId) {
        return executiveService.deleteByExecutiveId(executiveId) > 0 ? true:false;
    }
}
